/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jhtmlcleaner;

import core.Actions;
import core.HTMLCleaner;
import core.Setting;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFrame;

/**
 *
 * @author Victor
 */
public class jHTMLCheckBoxMenuItem extends JCheckBoxMenuItem{
    private Setting s;
    private JFrame f;
    public jHTMLCheckBoxMenuItem(JFrame f,final Setting s){
        super(s.toString(), s.getDefaultState());
        this.f=f;
        this.s=s;
    }
    public void execute(final HTMLCleaner cleaner){
       
        if(this.isSelected()){
            if(s.getType().equals(Actions.REPLACE_IMAGE_PATH)){
                ImagePathConfirmationDialog ipcd=new ImagePathConfirmationDialog(f, true,s.getParam1(),s.getParam2());
                ipcd.setVisible(true);
                switch(ipcd.getReturnStatus()){
                    case ImagePathConfirmationDialog.RET_OK:
                        String[] returnPaths=ipcd.returnPaths();
                        s.setTag(returnPaths[ ImagePathConfirmationDialog.PATH_TO_CHANGE]);
                        s.setAttribute(returnPaths[ ImagePathConfirmationDialog.NEW_PATH]);
                }
            }
            cleaner.executes(s);
        }
    }
    public Setting getSetting(){
        return s;
    }
    
//    public String getDescription(){
//        return action.toString();
//    }
//    public String getTag(){
//        return tag;
//    }
//    public String getAttribute(){
//        return attribute;
//    }
//    public void setAttribute(String attribute){
//        this.attribute=attribute;
//    }
}
